package com.singzi.leetcode.N1200;

import java.util.Arrays;
import java.util.Scanner;

public class T1153 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str1 = scanner.next();
        str1 = str1.substring(1, str1.length()-1);
        String str2 = scanner.next();
        str2 = str2.substring(1, str1.length()-1);
        System.out.println(getNum(str1, str2));
    }

    private static int getNum(String str1, String str2) {
        if(str1.equals(str2)) {
            return 0;
        }
        int[] left = new int[26], right = new int[26];
        Arrays.fill(left, -1);
        Arrays.fill(right, -1);
        for(int i = 0; i < str1.length(); i++) {
            int a = str1.charAt(i) - 'a', b = str2.charAt(i) - 'a';
            if(left[a] >= 0 && left[a] != b) {
                return -1;
            }
            left[a] = b;
            right[b] = a;
        }
        int cont = 0;
        for(int i : right) {
            if(i < 0) {
                cont++;
            }
        }
        return cont == 0?-1:26-cont;
    }
}
